package com.sangeng.controller;

import com.sangeng.annotation.SystemLog;
import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.dto.UserDto;
import com.sangeng.domain.entity.User;
import com.sangeng.domain.vo.UserInfoVo;
import com.sangeng.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    @GetMapping("/userInfo")
    public ResponseResult<UserInfoVo> userInfo() {
        return userService.userInfo();
    }

    @PutMapping("/userInfo")
    @SystemLog(businessName = "更新用户信息")
    public ResponseResult<String> updateUserInfo(@RequestBody User user) {
        //根据id更新用户信息
        return userService.updateUserInfo(user);
    }

    @PostMapping("/register")
    public ResponseResult<String> register(@RequestBody @Validated UserDto user) {// @Validated  留个坑 可以用 Spring Validation做校验 就没有那么多if语句 看起来爽
        return userService.register(user);
    }
}
